package com.li.java1;

import org.junit.Test;

import java.sql.SQLOutput;
import java.util.Comparator;

/**
 * @author 喂S别闹
 * @create 2022/4/20-10:03
 * @Version 1.0
 * @Description: Lambda表达式的介绍
 */
public class LambdaTest {

    @Test
    public void test1(){
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("测试");
            }
        };
        r1.run();
// -------------------------------------------------
        Runnable r2 = ()-> System.out.println("这是Lambda表达式");
        r2.run();
    }

    @Test
    public void test2(){
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };
        int compare = com1.compare(21, 22);
        System.out.println(compare);

//        ----------------------Lambda
        Comparator<Integer> com2 = (o1,o2) -> Integer.compare(o1,o2);
        int compare1 = com2.compare(22, 21);
        System.out.println(compare1);

        //        ----------------------方法引用
        Comparator<Integer> com3 = Integer::compare;
        int compare2 = com3.compare(22, 21);
        System.out.println(compare1);
    }

}
